// Copyright (C) Kumo inc. and its affiliates.
// Author: Jeff.li lijippy@163.com
// All rights reserved.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published
// by the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program.  If not, see <https://www.gnu.org/licenses/>.
//


#include <pollux/functions/registerer.h>
#include <pollux/functions/prestosql/json_functions.h>
#include <pollux/functions/prestosql/types/json_registration.h>

namespace kumo::pollux::functions {
    void registerJsonFunctions(const std::string &prefix) {
        registerJsonType();

        register_function<IsJsonScalarFunction, bool, Json>(
            {prefix + "is_json_scalar"});
        register_function<IsJsonScalarFunction, bool, Varchar>(
            {prefix + "is_json_scalar"});

        register_function<JsonExtractScalarFunction, Varchar, Json, Varchar>(
            {prefix + "json_extract_scalar"});
        register_function<JsonExtractScalarFunction, Varchar, Varchar, Varchar>(
            {prefix + "json_extract_scalar"});

        register_function<JsonArrayLengthFunction, int64_t, Json>(
            {prefix + "json_array_length"});
        register_function<JsonArrayLengthFunction, int64_t, Varchar>(
            {prefix + "json_array_length"});

        register_function<JsonArrayContainsFunction, bool, Json, bool>(
            {prefix + "json_array_contains"});
        register_function<JsonArrayContainsFunction, bool, Varchar, bool>(
            {prefix + "json_array_contains"});
        register_function<JsonArrayContainsFunction, bool, Json, int64_t>(
            {prefix + "json_array_contains"});
        register_function<JsonArrayContainsFunction, bool, Varchar, int64_t>(
            {prefix + "json_array_contains"});
        register_function<JsonArrayContainsFunction, bool, Json, double>(
            {prefix + "json_array_contains"});
        register_function<JsonArrayContainsFunction, bool, Varchar, double>(
            {prefix + "json_array_contains"});
        register_function<JsonArrayContainsFunction, bool, Json, Varchar>(
            {prefix + "json_array_contains"});
        register_function<JsonArrayContainsFunction, bool, Varchar, Varchar>(
            {prefix + "json_array_contains"});

        register_function<JsonSizeFunction, int64_t, Json, Varchar>(
            {prefix + "json_size"});
        register_function<JsonSizeFunction, int64_t, Varchar, Varchar>(
            {prefix + "json_size"});

        POLLUX_REGISTER_VECTOR_FUNCTION(udf_json_extract, prefix + "json_extract");

        POLLUX_REGISTER_VECTOR_FUNCTION(udf_json_format, prefix + "json_format");

        POLLUX_REGISTER_VECTOR_FUNCTION(udf_json_parse, prefix + "json_parse");

        POLLUX_REGISTER_VECTOR_FUNCTION(udf_json_array_get, prefix + "json_array_get");

        POLLUX_REGISTER_VECTOR_FUNCTION(
            udf_$internal$_json_string_to_array,
            prefix + "$internal$json_string_to_array_cast");

        POLLUX_REGISTER_VECTOR_FUNCTION(
            udf_$internal$_json_string_to_map,
            prefix + "$internal$json_string_to_map_cast");

        POLLUX_REGISTER_VECTOR_FUNCTION(
            udf_$internal$_json_string_to_row,
            prefix + "$internal$json_string_to_row_cast");
    }
} // namespace kumo::pollux::functions
